package zhanglinwei.cryptotools.core.wrapper;

import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.PropertySource;
import zhanglinwei.cryptotools.core.resolver.CryptoablePropertyResolver;
import zhanglinwei.cryptotools.core.source.CacheCryptoablePropertySource;
import zhanglinwei.cryptotools.core.source.CryptoablePropertySource;

public class CryptoableEnumerablePropertySourceWrapper<T> extends EnumerablePropertySource<T> implements CryptoablePropertySource<T> {

    private final CacheCryptoablePropertySource<T> cacheCryptoableDelegate;

    public CryptoableEnumerablePropertySourceWrapper(EnumerablePropertySource<T> delegate, CryptoablePropertyResolver resolver) {
        super(delegate.getName(), delegate.getSource());
        cacheCryptoableDelegate = new CacheCryptoablePropertySource<>(delegate, resolver);
    }

    @Override
    public PropertySource<T> getDelegate() {
        return cacheCryptoableDelegate;
    }

    @Override
    public Object getProperty(String name) {
        return cacheCryptoableDelegate.getProperty(name);
    }

    @Override
    public void refresh() {

    }

    @Override
    public String[] getPropertyNames() {
        return ((EnumerablePropertySource) cacheCryptoableDelegate.getDelegate()).getPropertyNames();
    }
}
